package com.haochu.xxl.animate;

import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

import com.haochu.xxl.model.PointItem;
import com.haochu.xxl.util.Constants;

/**
 * @author Administrator 元素掉落动画类
 */
public class FallAnimation extends Animation {
	// 游戏界面view
	private View view;
	// 元素点
	private PointItem point;
	// 元素点的原始y坐标
	private int py;
	// 移动步长，默认为1
	private int step;

	public FallAnimation(View view, PointItem point, int step) {
		this.point = point;
		this.py = point.getY();
		this.view = view;
		this.step = step;
		this.setDuration(200);
	}

	public FallAnimation(View view, PointItem point) {
		this(view, point, 1);
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		super.applyTransformation(interpolatedTime, t);
		if (interpolatedTime < 1.0f) {
			point.setY(py + (int) (Constants.SIZE * step * interpolatedTime));
		} else {
			point.setY(py + Constants.SIZE * step);
		}
		view.postInvalidate();
	}
}